import React, { useEffect } from 'react';
import {
    View, Text, TouchableOpacity,
} from 'react-native';
import { Modal } from '@ant-design/react-native';
import PropTypes from 'prop-types';
import Feather from 'react-native-vector-icons/Feather';
// import ReactNativeAN from 'react-native-alarm-notification';
import AntDesign from 'react-native-vector-icons/AntDesign';
import { isCheckImptask, delImptask } from '../../../../comconfig/sqlfun';
import styles from './styles';
import { debounce } from '../../../../utils/common';

const Item = ({
    navigation, title, rowid, impcode, checked, getList, alarmid,
}) => {
    const deleteTask = (id) => {
        delImptask(id);
    };

    useEffect(() => {

    }, []);
    const rowids = [parseInt(rowid, 10)];
    // const stopAlarmSound = () => {
    //     ReactNativeAN.stopAlarmSound();
    // };
    const Edit = () => (
        Modal.operation([
            {
                text: '删除',
                onPress: () => {
                    deleteTask(rowids);
                    getList();
                },
                style: { color: '#0F8DE9' },
            },
            {
                text: '详情',
                onPress: async () => {
                    await debounce(() => navigation.push('事务详情', {
                        rowid: parseInt(rowid, 10), getList,
                    }));
                },
                style: { color: '#0F8DE9' },
            },
            // {
            //     text: '停止闹钟',
            //     onPress: () => {
            //         stopAlarmSound();
            //     },
            //     style: { color: '#0F8DE9' },
            // },
        ])
    );
    return (
        <View>
            <TouchableOpacity
                onPress={async () => {
                    await isCheckImptask(parseInt(rowid, 10));
                    await getList();
                }}
                onLongPress={Edit}
            >
                <View style={styles.item}>
                    <View style={styles.text}>
                        <Text>
                            {
                                checked === 1
                                    ? <Feather name="check-square" size={22} />
                                    : <Feather name="square" size={22} />
                            }
                        </Text>
                        <Text style={{
                            fontSize: 18,
                            textDecorationLine: checked === 1 ? 'line-through' : 'none',
                        }}
                        >
                            {title}
                        </Text>
                    </View>
                    <View style={{ flexDirection: 'row', alignItems: 'center' }}>
                        {
                            parseInt(alarmid, 10) !== 0 ? (
                                <AntDesign
                                    name="bells"
                                    size={16}
                                    color="#017BFF"
                                    style={{ marginRight: 5 }}
                                />
                            ) : null
                        }
                        <Text style={{
                            color: impcode === '3' ? '#558666'
                                : impcode === '2' ? '#B8871E' : '#EA562B',
                            fontSize: 14,
                        }}
                        >
                            {impcode === '3' ? '一般' : impcode === '2' ? '重要' : '紧急'}
                        </Text>
                    </View>
                </View>
            </TouchableOpacity>
        </View>
    );
};
Item.defaultProps = {
    title: '',
    rowid: '',
    checked: 0,
    getList: '',
    impcode: '',
    alarmid: 0,
};
Item.propTypes = {
    title: PropTypes.string,
    rowid: PropTypes.string,
    impcode: PropTypes.string,
    checked: PropTypes.number,
    alarmid: PropTypes.number,
    getList: PropTypes.func,
};
export default Item;
